#include <vector>

#include "cData.h"

cData::cData(void) {}
cData::~cData(void){
    map<string, cTexture* >::iterator it;
    for(it=this->begin(); it!=this->end(); it++){
        delete (it->second);
    }
}

cTexture* cData::loadImage(const char*filename, int type, int wraps, int wrapt,
                        int magf, int minf, bool mipmap){
	cTexture* res=NULL;
	map<string, cTexture*>::iterator it;
        if((it=this->find(filename))!=this->end()){
			res=it->second;
        }else{
            cTexture * ctext = new cTexture();
            if(ctext->Load(filename, type, wraps, wrapt, magf, minf, mipmap)){
                res = ctext;
                (*this)[filename]=ctext;
            }else{
                delete ctext;
                res=NULL;
            }
        }
	return res;
}

cTexture* cData::loadImage(string &filename, int type, int wraps, int wrapt,
                        int magf, int minf, bool mipmap){
    return loadImage(filename.c_str(), type, wraps, wrapt, magf, minf, mipmap);
}